package ys.ewp.facade;

import java.io.File;
import java.io.FileOutputStream;

import org.springframework.stereotype.Component;

@Component
public class UploadFileFacade {

	public void uploadFile(byte[] content, String realName) throws Exception {
		String filePath = getClass().getClassLoader().getResource("/")
				.getFile();
		filePath = filePath.substring(0,
				(filePath.lastIndexOf("WEB-INF/classes/")));
		File file = new File(filePath + "file\\");
		if (!file.exists())
			file.mkdirs(); // 如果目录不存在就新建
		File filePro = new File(filePath + "file\\" + realName);
		FileOutputStream stream = new FileOutputStream(filePro);
		if (content != null) {
			stream.write(content);
			stream.close();
		}
	}
}
